package com.lesent.kafka.config;

import com.lesent.model.entity.Student;
import com.lesent.model.utils.JsonUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.kafka.annotation.KafkaListener;

import java.io.IOException;

/**
 * @author shengtao
 * @Description:
 * @date 2018/08/14 16:38
 */

public class Listener {
    protected final Logger logger = LoggerFactory.getLogger(this.getClass());

    @KafkaListener(topics = {"${kafka.producer.deafaultTopic}"},groupId = "${kafka.consumer.groupId}")
    public void listen(ConsumerRecord<?, ?> record) {
        logger.info("kafka的key: " + record.key());
        try {
            Student student = JsonUtils.json2Obj(record.value().toString(),Student.class);
            logger.info("kafka的value: " + student.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
